package com.ncmmall.application.business.goods;

import com.ncmmall.domain.business.goods.unit.GoodsUnit;
import com.ncmmall.domain.business.goods.unit.GoodsUnitRepository;
import com.ncmmall.domain.business.goods.unit.QGoodsUnit;
import com.ncmmall.querychannel.service.QueryChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author linxs
 * @Description: 商品单位
 * @Date: 2020-04-10 17:26
 */
@Service
@Transactional
public class GoodsUnitApplication {

    @Autowired
    private GoodsUnitRepository unitRepository;

    @Autowired
    private QueryChannelService queryChannelService;

    /**
     * 添加
     */
    public void create(GoodsUnit unit) {
        unit.setStatus(1);
        unitRepository.save(unit);
    }

    /**
     * 修改
     */
    public void modify(GoodsUnit params) {
        GoodsUnit unit = queryChannelService.findOne(QGoodsUnit.goodsUnit.id.eq(params.getId()), GoodsUnit.class);
        unit.setName(params.getName());
        unitRepository.save(unit);
    }

    /**
     * 删除
     */
    public void remove(GoodsUnit params) {
        GoodsUnit unit = queryChannelService.findOne(QGoodsUnit.goodsUnit.id.eq(params.getId()), GoodsUnit.class);
        unit.setStatus(2);
        unitRepository.save(unit);
    }


}
